/**
 * 
 */
package org.compiere.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

/**
 * @author V.Sokolov
 *
 */
public class Mhrmhealthinsurance extends X_hrm_healthinsurance {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1296279703450331623L;
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mhrmhealthinsurance.class);

	/**
	 * @param ctx
	 */
	public Mhrmhealthinsurance(Properties ctx) {
		super(ctx);
	}
	
	/**
	 * @param ctx
	 * @param hrm_healthinsurance_ID
	 * @param trxName
	 */
	public Mhrmhealthinsurance(Properties ctx, int hrm_healthinsurance_ID,
			String trxName) {
		super(ctx, hrm_healthinsurance_ID, trxName);
	}
	
	/**
	 * @param ctx
	 * @param rs
	 * @param trxName
	 */
	public Mhrmhealthinsurance(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
	}

	public static Mhrmhealthinsurance[] getMedInsuranceList(int C_BPartner_ID) {
		
		//
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		Mhrmhealthinsurance hrmcer = null;
			
		ArrayList<Mhrmhealthinsurance> list = new ArrayList<Mhrmhealthinsurance>();
		// 
			String sql_ = "SELECT * FROM HRM_HEALTHINSURANCE T \n" +
					"WHERE T.AD_CLIENT_ID=? \n" +
					"AND T.C_BPARTNER_ID=? \n" +
					"ORDER BY T.STARTDATE";
			try
			{
				pstmt = DB.prepareStatement(sql_,null);
				pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
				pstmt.setInt(2, C_BPartner_ID);
				rs = pstmt.executeQuery();	
				while(rs.next()){
					hrmcer = new  Mhrmhealthinsurance(Env.getCtx(), rs, null);
					list.add(hrmcer);
				}
			}
			catch (SQLException e)
			{
				s_log.log(Level.SEVERE, "product", e);
			}
			finally
			{
				DB.close(rs, pstmt);
				rs = null; pstmt = null;
			}	
			
			return list.toArray(new Mhrmhealthinsurance[list.size()]);
		
	}

}
